import {repGoodsInfo,reqAddShopCar} from '@/api'
import { getUUID } from '@/utils/uuid_token'

const state ={
    goodsInfo: {},
    // 游客临时身份
    uuid_token: getUUID()
}
const mutations ={
    GETGOODSINFO(state,goodsInfo){
        state.goodsInfo = goodsInfo
    }
}
const actions = {
    async getGoodsInfo({commit},skuId){
        const result = await repGoodsInfo(skuId)
        if(result.code === 200){
            commit('GETGOODSINFO',result.data)
        }
    },
    async getAddShopCar({commit},{skuId,skuNum}){
        const result = await reqAddShopCar(skuId,skuNum)
        if(result.code === 200){
           return 
        }else{
            return Promise.reject(new Error('faile'))
        }
       
    } 
}

const getters ={
    categoryView(state){
        return state.goodsInfo.categoryView || {}
    },
    skuInfo(state){
        return state.goodsInfo.skuInfo || {}
    },
    spuSaleAttrList(state){
        return state.goodsInfo.spuSaleAttrList || []
    }

}
export default {
    state,
    actions,
    mutations,
    getters
}